<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
        margin: 0;
        padding: 0;
        text-align: center;
    }

    .title {
        margin-bottom: 20px;
    }

    .user {
        width: 50vw;
        height: 20vh;
        border: 1px solid rgb(84, 204, 114);
        margin: 50px auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
        .btn{
            width: 100px;
            height: 100px;
            background-color: aquamarine;
            border: 0;

        }
    </style>
</head>
<body>
    <h1 id="title">学生个人信息:&nbsp;姓名:孙永航,学号:2022020311,班级:计算计应用技术7班。</h1>
    <div class="user">
        <span>姓名</span><input type="text" name="username" id="username">
        <span>班级</span><input type="text" name="oldname" id="oldname">
        <span>学号</span><input type="text" name="addr" id="addr">
       
        <br>
    </div>
    
    <button class="btn" onclick="sendReg()">点击按钮<br>发送get请求<br>,测试页面效果</button>
</body>
</html>
<script>
    function sendReg(){
        let title = document.querySelector('#title')
        let name = document.querySelector('#username').value
        let oldname = document.querySelector('#oldname').value
        let addr = document.querySelector('#addr').value
        let url = 'http://127.0.0.1:3000/user?username=' + name + '&addr=' + addr+'&oldname='+ oldname
        let http = new XMLHttpRequest()

        http.open('get',url)
        http.send()
        http.onreadystatechange = function(){
            if(http.readyState === 4){
                if(http.status >= 200 && http.status < 300){
                    title.innerHTML = JSON.parse(http.responseText).welcome
                }
            }
        }
        
    }
</script>